﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace HCFramework.Control.HtmlControlStaticVer
{
    public partial class HtmlControlStaticVer : System.Web.UI.UserControl
    {
        public string FileName
        {
            get
            {
                return litFileName.Text;
            }
            set
            {
                litFileName.Text = value;
            }
        }

        private string filePath
        {
            get
            {
                string filePath = Server.MapPath("~/Control/HtmlControlStaticVer/File/") + FileName + "." + C.LanguageController.GetLanguageCurrent() + ".html";
                if (!File.Exists(filePath)) M.FileM.Write(filePath,"");
                return filePath;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (FileName == "")
            {
                M.Message.ShowError("Chưa gán thuộc tính FileName");
                return;
            }
            if (!IsPostBack)
            {
                LoadContent();
            }
        }

        private void LoadContent()
        {
            string content = File.ReadAllText(filePath);
            litContent.Text = content;
            linkEdit.Visible = C.UserController.IsAdmin();
            linkEdit.NavigateUrl = "/Control/HtmlControlStaticVer/Edit.aspx?fileName="+FileName;
        }
    }
}